package com.sevattal.service.leaves.controller;


import com.sevattal.common.base.result.R;
import com.sevattal.service.leaves.entity.vo.InspectionArrivalOrderVo;
import com.sevattal.service.leaves.entity.vo.InspectionArrivalOrderVo;
import com.sevattal.service.leaves.service.InspectionArrivalOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  检验到货主表 前端控制器
 * </p>
 *
 * @author Sevattal
 * @since 2021-08-28
 */
@Api(tags = "质检管理")
@RestController
@RequestMapping("/admin/leaves/inspection-arrival-order")
public class InspectionArrivalOrderController {

    @Autowired
    private InspectionArrivalOrderService inspectionService;


    @ApiOperation("新建质检单")
    @PostMapping("createInspectionOrder")
    public R createinspectionOrder(@ApiParam(value = "质检单对象",required = true) @RequestBody InspectionArrivalOrderVo inspectionOrderVo){
        boolean result = inspectionService.createInspectionOrder(inspectionOrderVo);
        if (result) {
            return R.ok().message("创建成功");
        }else{
            return R.error().message("创建失败");
        }
    }

    @ApiOperation("修改质检单")
    @PutMapping("updateInspectionOrder")
    public R updateInspectionOrder(@ApiParam(value = "质检到货单对象",required = true) @RequestBody InspectionArrivalOrderVo inspectionOrderVo) {
        boolean result = inspectionService.updateInspectionOrder(inspectionOrderVo);
        if (result) {
            return R.ok().message("修改成功");
        }else{
            return R.error().message("修改失败");
        }
    }

    @ApiOperation("删除质检单")
    @DeleteMapping("deleteInspectionOrder/{id}")
    public R deleteInspectionOrder(@ApiParam(value = "质检单ID",required = true) @PathVariable String id) {
        boolean result = inspectionService.deleteInspectionOrder(id);
        if (result) {
            return R.ok().message("删除成功");
        }else{
            return R.error().message("删除失败");
        }
    }


    @ApiOperation("获取质检信息")
    @PostMapping("getInspectionOrderList")
    public R getInspectionOrderList(@ApiParam(value = "质检单对象",required =  true)  @RequestBody InspectionArrivalOrderVo inspectionOrderVo){
        List<InspectionArrivalOrderVo> inspectionOrderVoList = inspectionService.getInspectionOrderList(inspectionOrderVo);
        return R.ok().data("inspectionOrderVoList",inspectionOrderVoList);
    }

    @ApiOperation("确认出入库")
    @PostMapping("confirmInspectionOrder/{id}")
    public R confirmInOutOrder(@ApiParam(value = "确认质检订单id",required = true) @PathVariable String id ){
        boolean result = inspectionService.confirmInspectionOrder(id);
        if (result) {
            return R.ok().message("确认成功");
        }else{
            return R.error().message("确认失败");
        }
    }

}

